package com.huluobo.a2109mvpimdemo.conversation;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.huluobo.a2109mvpimdemo.chat.ChatActivity;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMConversation;
import com.hyphenate.easeui.modules.conversation.EaseConversationListFragment;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class ConversationFragment extends EaseConversationListFragment {
//    private List<EMConversation> conversations;

    @Override
    public void onItemClick(View view, int position) {
        super.onItemClick(view, position);
        String conversationId = ((EMConversation) conversationListLayout.getItem(position).getInfo())
                .conversationId();

//        String conversationId = conversations.get(position).conversationId();

        int chatType = 0;
        switch (((EMConversation) conversationListLayout.getItem(position).getInfo()).getType()) {
//        switch (conversations.get(position).getType()) {
            case Chat:
                chatType = 1;
                break;
            case GroupChat:
                chatType = 2;
                break;
        }

        Intent intent = new Intent(getActivity(), ChatActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("conversationId", conversationId);
        bundle.putInt("chatType", chatType);
        intent.putExtras(bundle);
        getActivity().startActivity(intent);
    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
//        Map<String, EMConversation> allConversations = EMClient.getInstance().chatManager().getAllConversations();
//        conversations = new ArrayList<>(allConversations.values());
    }
}